
import UIKit

class FFSimpleTextPopup: UIView {
    
    init(_ message: String, textColor: UIColor, textFont: UIFont) {
        super.init(frame: UIScreen.main.bounds)
        
        backgroundColor = UIColor(white: 0, alpha: 0.8)
        
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        label.text = message
        label.textColor = textColor
        label.numberOfLines = 0
        label.font = textFont
        
        addSubview(label)
        
        NSLayoutConstraint.activate([
            label.centerXAnchor.constraint(equalTo: centerXAnchor),
            label.centerYAnchor.constraint(equalTo: centerYAnchor),
            label.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: 20),
            label.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -20)
        ])
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func show() {
        DispatchQueue.main.async {
            if let windowScene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene,
               let window = windowScene.windows.first(where: { $0.isKeyWindow }) {
                window.addSubview(self)
                
                DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
                    self.removeFromSuperview()
                }
            }
        }
    }
}
